<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
    window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
    return window.navigator.bluetooth.requestDevice({
        filters: [{services: [heart_rate.name]}],
        optionalServices: [generic_access.name]
    })
    .then(device => device.gatt.connect())
    .then(gattServer => Promise.all([
        gattServer.getPrimaryService(generic_access.name),
        gattServer.getPrimaryService(generic_access.name)]))
    .then(services => {
        for (let i = 1; i < services.length; i++) {
            assert_equals(services[0], services[i],
                          'Should return the same service as the first call.');
        }
    });
}, 'Calls to get the same service should return the same object.');
</script>
